#include <iostream>
using namespace std;
class Person
{
public:
	Person()
	{
		cout<<"Person()"<<endl;
	}
	Person(int a)
	{
		cout<<"Person(int a)"<<endl;
	}
	Person(const Person & p)
	{
		cout<<"Person(Person p)"<<endl;
		b = p.b;
	}
	~Person()
	{
		cout<<"~Person()"<<endl;
	}
	void func2()const;
	static void func()
	{
		cout<<"func"<<endl;
		// b = 30; // error
		a = 10;
	}
	static int a;
	int b = 20;
	mutable int c;
};
int Person::a = 10;
void Person::func2() const
{
	this->c = 100;
	cout<<this->c<<endl;
}
Person doWork()
{
	Person p;
	// cout<<(int*)&p<<endl;
	// 返回新对象，而不是p
	return p;
}
int main(int argc, char const *argv[])
{
	/*
	cout<<Person::a<<endl;
	Person::func();
	// 括号法
	Person p1;
	Person p2(2);
	// 显示法
	Person p3;
	Person p4 = Person(3); //调用有参构造
	Person(1); // 匿名对象, 代码执行过后会被系统立即回收
	// Person(p4); // error
	// 隐式转换法
	Person p5 = 10; // Person p5 = Person(10)
	Person p6 = p5;
	*/

	// 拷贝构造函数
	cout<<"function"<<endl;
	// 值方式返回局部对象
	Person p = doWork();
	Person p7 = doWork();
	// cout<<(int*)&p7<<endl;
	// cout<<sizeof(p7)<<endl; // 只有非静态成员函数属于某个对象
	// cout<<p7.a<<endl;
	// Person * p8 = new Person;
	// p8->a = 20;
	cout<<p7.a<<endl;
	p7.func2();
	// const Person p9; // 对象值不能改，而且常量对象只能调用常函数
	return 0;
}